<?php #//AJAX PHP PENNY AUCTION v.1.2.2

#///////////////////////////////////////////////////////////
#//  COPYRIGHT 2009 Aaron Helmlinger ALL RIGHTS RESERVED  //
#///////////////////////////////////////////////////////////
                        include "../includes/config.inc.php";
                        
include "loggedin.inc.php";

      
             
                               
          if($_POST[update])  {
       
       $activated = $_POST[activated];
       $auctionid = $_POST[auctionid];  
       $refund_percentage = $_POST[percentage]; 
       
       
   if($activated == 1)  {     
       
     echo $MSG_AJAX_ADMIN_AUCTION_REFUND_BIDS_PROGRAM_MESSAGE1;

$query = "SELECT bidder,current_high_bidder from PHPAUCTIONXL_bids2 where auction=$auctionid";
$result = mysql_query($query);
$num_auction = mysql_num_rows($result);




   
 $i = 0;
while($i < $num_auction) {
 
                     

 $userid = mysql_result($result,$i,"bidder"); 
   $current_high_bidder = mysql_result($result,$i,"current_high_bidder");


$query_bids_remaining = "select bids_remaining from PHPAUCTIONXL_users where id=$userid";
                             $query_bids_remaining2 =  mysql_query ($query_bids_remaining);
                                $bids_remaining = mysql_result($query_bids_remaining2,0,"bids_remaining");
  
  
  $bids2refund = 1 * ( $refund_percentage / 100 );
  
 $bids_remaining_updated = $bids_remaining + $bids2refund; 
  
$query2="UPDATE PHPAUCTIONXL_users SET bids_remaining='$bids_remaining_updated' WHERE id=$userid";
     
mysql_query($query2);
 
$i++;
}



$query = "SELECT bidder,current_high_bidder from PHPAUCTIONXL_bids2 where auction=$auctionid";
$result = mysql_query($query);
$num_auction = mysql_num_rows($result);

 $i = 0;
while($i < $num_auction) {
 
                     

 $userid = mysql_result($result,$i,"bidder"); 
   $current_high_bidder = mysql_result($result,$i,"current_high_bidder");


$query_bids_remaining = "select bids_remaining from PHPAUCTIONXL_users where id=$userid";
                             $query_bids_remaining2 =  mysql_query ($query_bids_remaining);
                                $bids_remaining = mysql_result($query_bids_remaining2,0,"bids_remaining");
  
$bids_remaining_updated = ceil($bids_remaining);
    
$query2="UPDATE PHPAUCTIONXL_users SET bids_remaining='$bids_remaining_updated' WHERE id=$userid";
     
mysql_query($query2);
 
echo $MSG_AJAX_ADMIN_AUCTION_REFUND_BIDS_PROGRAM_MESSAGE2;
echo $current_high_bidder;
echo "<BR>";

$i++;
}










$query3="UPDATE PHPAUCTIONXL_auctions SET refund=1 WHERE id=$auctionid";
     
mysql_query($query3);


        echo "<H1><font color=red >";
        echo $refund_percentage;
        echo " % ";
            echo $MSG_AJAX_ADMIN_AUCTION_REFUND_BIDS_PROGRAM_MESSAGE3;
        echo "<BR>";
        echo $MSG_AJAX_ADMIN_AUCTION_REFUND_BIDS_PROGRAM_MESSAGE4;
         echo "</font>";
          $iupdated = $i * ( $refund_percentage / 100 );
          $iupdated2 = ceil($iupdated);
         
         echo $iupdated2;
         echo "</h1>";
         
         }
       
       if ($activated == 0 )  {
      
       
       $URL = $_SESSION["RETURN_LIST"]."?offset=".$_SESSION['RETURN_LIST_OFFSET'];
	unset($_SESSION["RETURN_LIST"]);
	header("Location: $URL");
	exit;
       
       }
       
       
               }
       
       
       
 if(!$_POST[update])  {                            
    
     
       
      
        $auctionid = $_GET['id'];
      
         $query_title = "select title from PHPAUCTIONXL_auctions where id=$auctionid";
                             $query_title2 =  mysql_query ($query_title);
                                $auction_title = mysql_result($query_title2,0,"title");
                                                   
                                
           
           
        $ERR = $MSG_AJAX_ADMIN_AUCTION_REFUND_BIDS_FOR_AUCTION_ERROR;
        $ERR .= $auction_title;   
                                
         
  ?>
  
  
  
  


<HTML>
<HEAD>
<link rel='stylesheet' type='text/css' href='style.css' />
<link href="css/main.css" rel="stylesheet" type="text/css">
</HEAD>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">





<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr> 
    <td>
    
       <? // -------------------------- Admin Tool Heading --------------------------------------?>
       
       
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="titulo">
        <tr> 

  <td class="icono"><img src="images/auction_icon2.gif" width="31" height="25" ></td>
          <td class="breadcrumbs"><p><span><?=$MSG_239?></span>&nbsp;&gt;&gt;&nbsp;<?=$MSG_AJAX_ADMIN_AUCTION_REFUND_BIDS_FOR_AUCTION?></p></td>
        </tr>
      </table>
      
      
      
      </td>
  </tr>
  <tr>
    <td align="center" valign="middle">&nbsp;</td>
  </tr>
    <tr> 
    <td align="center" valign="middle">
    
    
    
<TABLE BORDER=0 WIDTH=100% CELLPADDING=0 CELLSPACING=0 BGCOLOR="#FFFFFF">
<TR>
<TD align="center">
<BR>
<FORM NAME=conf ACTION=<?=basename($_SERVER['PHP_SELF'])?> METHOD=POST>


  <? // -------------------------- LIGHT BLUE TITLE BAR --------------------------------------?>

	<TABLE WIDTH="95%" BORDER="0" CELLSPACING="0" CELLPADDING="0"  class="base" ALIGN="CENTER" style="border:1px solid #ccc;">
		<TR>
			<TD ALIGN=CENTER class=title>
				<p><? print $MSG_AJAX_ADMIN_AUCTION_REFUND_BIDS_FOR_AUCTION; ?></p>
			</TD>
		</TR>
		
		
		
		<TR>
		<TD>
		
    
    
    <TABLE WIDTH=100% ALIGN="CENTER" CELLPADDING=0 cellspacing="0" BGCOLOR="#FFFFFF">
		
 <? // -------------------------- ERROR BAR --------------------------------------?>    
 
 <? if ($ERR) { ?>   
    	<TR>
				<TD COLSPAN="2"  class="error"><B>
					<p><? print $ERR; ?></p>
					</B></TD>
			</TR>
	<? } ?>	
    
    	
			
			
 <? // -------------------------- WHITE BAR --------------------------------------?> 			
				
        <TR>
        <TD WIDTH="125"> 
					<p class="blue"><? print $MSG_AJAX_ADMIN_AUCTION_REFUND_BIDS_FOR_AUCTION_QUESTION; ?>
            
          <BR>
          
          </p>
					</TD>
					
					
				<TD WIDTH="405">
				
					
					 
<input type="radio" name="activated" value="1" <? if ( $activated == 1 ) echo checked ?> /> YES &nbsp;&nbsp; <input type="radio" name="activated" value="0" <? if ( $activated == 0 ) echo checked ?> /> NO  &nbsp;&nbsp;&nbsp;&nbsp;

			
				 </TD>
			</TR>
			
			
			
			
			
			<? // -------------------------- GREY BAR --------------------------------------?>	
			
			<TR>
				<TD WIDTH="125" class="gris">
					<p class="blue">Enter Percentage (%) Of Bids To Rufund Each User</p>
					</TD>
				<TD WIDTH="405" class="gris">


             <input type=text name=percentage > e.g. 10 for 10%
					
				</TD>
			</TR>				 

		</TABLE>
		  <INPUT TYPE=hidden NAME=auctionid VALUE=<? print $_GET['id']; ?> >
		  <INPUT TYPE=hidden NAME=update VALUE=1 >
		        <INPUT TYPE="submit" NAME="act" VALUE="<? print $MSG_AJAX_ADMIN_AUCTION_REFUND_BIDS_BUTTON; ?>" class="action">
		 </form>
		
		</TD>
		</TR>
	</TABLE>
	</FORM>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>

<? } ?>

</BODY>
</HTML>
